package com.wubo.sec.acl;


import com.wubo.sec.SecurityManager;
import com.wubo.sec.acl.core.AclManager;
import com.wubo.sec.acl.core.EntityAcl;
import com.wubo.sec.core.UserData;
import com.wubo.sec.model.Role;

/**
 * 
 * @author WuBo
 * @CreateDate 2012-4-23
 */
public class RoleAcl extends EntityAcl {
	private Role role;
	public RoleAcl(Role role){
		this.role = role;
	}
	
	@Override
	public int getAcl() {
		UserData user = SecurityManager.getCurrentUser();
		if(user == null){
			return 0;
		}
		if(SecurityManager.isAdmin() || SecurityManager.hasAdminAuth(user)){
			return AclManager.getInstance().getAllAcl();
		}else{
			if(role.getOwner().equals(user.getUsername())
					&& (! SecurityManager.isMarkLocked() || !role.isLocked()) ){
				return AclManager.getInstance().getAllAcl();
			}
			return 0;
		}
	}
	
}
